package com.example.rk.service.impl;

import com.example.rk.common.MyPageInfo;
import com.example.rk.entity.Job;
import com.example.rk.entity.User;
import com.example.rk.mapper.UserMapper;
import com.example.rk.service.UserService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper mapper;
    @Override
    public void deleteById(int id) {
        mapper.deleteById(id);
    }

    @Override
    public User findById(int id) {
        return mapper.findByID(id);
    }

    @Override
    public MyPageInfo findBySearch1(HttpServletRequest request, int id) {
        int currentPageNum=1;  //当前页
        int pageSize=5;  //每页大小
        String currentPageNumStr = request.getParameter("pageNum");
        if (currentPageNumStr!=null){
            currentPageNum=Integer.parseInt(currentPageNumStr);
        }
        String gsname = request.getParameter("gsname");
        String position = request.getParameter("position");
        Page<Object> page = PageHelper.startPage(currentPageNum, pageSize);//必须在执行sql之前执行
        mapper.findBySearch1(gsname,position,id);
        PageInfo<Object> pageInfo = page.toPageInfo();
        MyPageInfo myPageInfo = new MyPageInfo(pageInfo.getPageNum(),pageInfo.getPageSize(),
                pageInfo.getNavigateLastPage(),pageInfo.getTotal(),pageInfo.getList());


        myPageInfo.setSearch1(gsname);
        myPageInfo.setSearch2(position);

        return myPageInfo;
    }

    @Override
    public MyPageInfo findBySearch2(HttpServletRequest request, int cid) {
        int currentPageNum=1;  //当前页
        int pageSize=5;  //每页大小
        String currentPageNumStr = request.getParameter("pageNum");
        if (currentPageNumStr!=null){
            currentPageNum=Integer.parseInt(currentPageNumStr);
        }
        String xsname = request.getParameter("xsname");
        String position =request.getParameter("position");
        Page<Object> page = PageHelper.startPage(currentPageNum, pageSize);//必须在执行sql之前执行
        mapper.findBySearch2(xsname,position,cid);
        PageInfo<Object> pageInfo = page.toPageInfo();
        MyPageInfo myPageInfo = new MyPageInfo(pageInfo.getPageNum(),pageInfo.getPageSize(),
                pageInfo.getNavigateLastPage(),pageInfo.getTotal(),pageInfo.getList());
        myPageInfo.setSearch1(xsname);
        myPageInfo.setSearch2(position);
        return myPageInfo;
    }

    @Override
    public String doEdit1(int id) {
        try {
            mapper.doEdit1(id);
            return "ok";
        }catch (Exception e){
            System.out.println("RenKoServiceImpl.doEdit() ERROR:e="+e);
        }
        return "error";

    }

    @Override
    public String doEdit2(int id) {
        try {
            mapper.doEdit2(id);
            return "ok";
        }catch (Exception e){
            System.out.println("RenKoServiceImpl.doEdit() ERROR:e="+e);
        }
        return "error";

    }

    @Override
    public void doAdd1(User user) {
            mapper.create1(user);
    }

    @Override
    public void doAdd2(User user) {
           mapper.create2(user);
    }

    @Override
    public String getinformation(int id) {
        return mapper.getinformation(id);
    }

    @Override
    public String getposition(int id) {
        return mapper.getposition(id);
    }

    @Override
    public int getsid(int id) {
        return mapper.getsid(id);
    }

    @Override
    public int getcid(int id) {
        return mapper.getcid(id);
    }

    @Override
    public String getname(int id) {
        return mapper.getname(id);
    }

    @Override
    public String getposition2(int id) {
        return mapper.getposition2(id);
    }

    @Override
    public MyPageInfo findBySearchxs(HttpServletRequest request, int id) {
        int currentPageNum=1;  //当前页
        int pageSize=5;  //每页大小
        String currentPageNumStr = request.getParameter("pageNum");
        if (currentPageNumStr!=null){
            currentPageNum=Integer.parseInt(currentPageNumStr);
        }
        int zt=1;
        String gsname = request.getParameter("gsname");
        String position = request.getParameter("position");
        Page<Object> page = PageHelper.startPage(currentPageNum, pageSize);//必须在执行sql之前执行
        mapper.findBySearchxs(gsname,position,id,zt);
        PageInfo<Object> pageInfo = page.toPageInfo();
        MyPageInfo myPageInfo = new MyPageInfo(pageInfo.getPageNum(),pageInfo.getPageSize(),
                pageInfo.getNavigateLastPage(),pageInfo.getTotal(),pageInfo.getList());


        myPageInfo.setSearch1(gsname);
        myPageInfo.setSearch2(position);

        return myPageInfo;
    }

    @Override
    public MyPageInfo findBySearchgs(HttpServletRequest request, int id) {
        int currentPageNum=1;  //当前页
        int pageSize=5;  //每页大小
        String currentPageNumStr = request.getParameter("pageNum");
        if (currentPageNumStr!=null){
            currentPageNum=Integer.parseInt(currentPageNumStr);
        }
        String xsname = request.getParameter("xsname");
        String position =request.getParameter("position");
        int zt=0;
        Page<Object> page = PageHelper.startPage(currentPageNum, pageSize);//必须在执行sql之前执行
        mapper.findBySearchgs(xsname,position,id,zt);
        PageInfo<Object> pageInfo = page.toPageInfo();
        MyPageInfo myPageInfo = new MyPageInfo(pageInfo.getPageNum(),pageInfo.getPageSize(),
                pageInfo.getNavigateLastPage(),pageInfo.getTotal(),pageInfo.getList());


        myPageInfo.setSearch1(xsname);
        myPageInfo.setSearch2(position);

        return myPageInfo;
    }

    @Override
    public String getgsphone(int id) {
        return mapper.getgsphone(id);
    }

    @Override
    public String getxsphone(int id) {
        return mapper.getxsphone(id);
    }

    @Override
    public MyPageInfo findBySearchxs1(HttpServletRequest request, int id) {
        int currentPageNum=1;  //当前页
        int pageSize=5;  //每页大小
        String currentPageNumStr = request.getParameter("pageNum");
        if (currentPageNumStr!=null){
            currentPageNum=Integer.parseInt(currentPageNumStr);
        }
        int zt=3;
        String gsname = request.getParameter("gsname");
        String position = request.getParameter("position");
        Page<Object> page = PageHelper.startPage(currentPageNum, pageSize);//必须在执行sql之前执行
        mapper.findBySearchxs(gsname,position,id,zt);
        PageInfo<Object> pageInfo = page.toPageInfo();
        MyPageInfo myPageInfo = new MyPageInfo(pageInfo.getPageNum(),pageInfo.getPageSize(),
                pageInfo.getNavigateLastPage(),pageInfo.getTotal(),pageInfo.getList());


        myPageInfo.setSearch1(gsname);
        myPageInfo.setSearch2(position);

        return myPageInfo;
    }

    @Override
    public MyPageInfo findBySearchgs1(HttpServletRequest request, int id) {
        int currentPageNum=1;  //当前页
        int pageSize=5;  //每页大小
        String currentPageNumStr = request.getParameter("pageNum");
        if (currentPageNumStr!=null){
            currentPageNum=Integer.parseInt(currentPageNumStr);
        }
        String xsname = request.getParameter("xsname");
        String position =request.getParameter("position");
        int zt=3;
        Page<Object> page = PageHelper.startPage(currentPageNum, pageSize);//必须在执行sql之前执行
        mapper.findBySearchgs(xsname,position,id,zt);
        PageInfo<Object> pageInfo = page.toPageInfo();
        MyPageInfo myPageInfo = new MyPageInfo(pageInfo.getPageNum(),pageInfo.getPageSize(),
                pageInfo.getNavigateLastPage(),pageInfo.getTotal(),pageInfo.getList());


        myPageInfo.setSearch1(xsname);
        myPageInfo.setSearch2(position);

        return myPageInfo;
    }
}
